package cn.yuanqiao.web.controller.archive.liyong;

import java.util.ArrayList;
import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import cn.yuanqiao.archive.liyong.domain.YqdyDa;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.yuanqiao.common.annotation.Log;
import cn.yuanqiao.common.enums.BusinessType;

import cn.yuanqiao.archive.liyong.domain.YqDy;
import cn.yuanqiao.archive.liyong.service.IYqDyService;
import cn.yuanqiao.common.web.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.utils.poi.ExcelUtil;
import cn.yuanqiao.common.web.page.TableDataInfo;

/**
 * 我的订阅Controller
 * 
 * @author sy
 * @date 2023-08-10
 */
@RestController
@RequestMapping("/archive/yqdy")
public class YqDyController extends BaseController
{
    @Autowired
    private IYqDyService yqDyService;

    /**
     * 查询我的订阅列表
     */
//    @PreAuthorize("@ss.hasPermi('archive:yqdy:list')")
    @GetMapping("/list")
    public TableDataInfo list(YqDy yqDy)
    {
        startPage();
        List<YqDy> list = yqDyService.selectYqDyList(yqDy);
        return getDataTable(list);
    }

    /**
     * 导出我的订阅列表
     */
    @PreAuthorize("@ss.hasPermi('archive:yqdy:export')")
    @Log(title = "我的订阅", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YqDy yqDy)
    {
        List<YqDy> list = yqDyService.selectYqDyList(yqDy);
        ExcelUtil<YqDy> util = new ExcelUtil<YqDy>(YqDy.class);
        util.exportExcel(response, list, "我的订阅数据");
    }

    /**
     * 获取我的订阅详细信息
     */
//    @PreAuthorize("@ss.hasPermi('archive:yqdy:query')")
    @GetMapping(value = "/query")
    public TableDataInfo getInfo(YqDy yqDy)
    {
        if (yqDy.getDyId() == null || yqDy.getDyId() ==0) {
            yqDy=yqDyService.selectYqDyByDyGjc(yqDy);
        }
        startPage();
        Map<String, List> map = yqDyService.selectYqDyByDyId(yqDy.getDyId());
        List<Map> list = map.get("result");
        List<String> testArray = map.get("yqdyDaList");
        int total = getDataTable(testArray).getTotal();
        TableDataInfo dataTable = getDataTable(list);
        dataTable.setTotal(total);
        return dataTable;
    }

    /**
     * 新增我的订阅
     */
//    @PreAuthorize("@ss.hasPermi('archive:yqdy:add')")
    @Log(title = "我的订阅", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YqDy yqDy)
    {
        return success(yqDyService.insertYqDy(yqDy));
    }

    /**
     * 修改我的订阅
     */
//    @PreAuthorize("@ss.hasPermi('archive:yqdy:edit')")
    @Log(title = "我的订阅", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YqDy yqDy)
    {
        return toAjax(yqDyService.updateYqDy(yqDy));
    }

    /**
     * 删除我的订阅
     */
//    @PreAuthorize("@ss.hasPermi('archive:yqdy:remove')")
    @Log(title = "我的订阅", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dyIds}")
    public AjaxResult remove(@PathVariable Long[] dyIds)
    {
        return toAjax(yqDyService.deleteYqDyByDyIds(dyIds));
    }

    /**
     * 获取门类ID
     */
//    @PreAuthorize("@ss.hasPermi('archive:yqdy:categoryId')")
    @Log(title = "我的订阅", businessType = BusinessType.SELECT)
    @PostMapping("/categoryId")
    public AjaxResult selectTenantCategoryByTableName(@RequestBody YqdyDa yqdyDa)
    {
        return yqDyService.selectTenantCategoryByTableName(yqdyDa);
    }
}
